package com.hiquety.tcb.ui;

import com.hiquety.tcb.config.AppInfo;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Font;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class AboutUI {
    public static Stage stage = new Stage();
    public static AnchorPane anchorPane = new AnchorPane();
    public static Scene scene = new Scene(anchorPane);
    public static ImageView imageView = new ImageView(AppInfo.ICON_PATH);
    public static Label T_VERSION = new Label("版本：");
    public static Label T_AUTHOR = new Label("作者：");
    public static Label T_EMAIL = new Label("邮箱：");
    public static Label T_TIME = new Label("更新：");

    public static Label title = new Label(AppInfo.TITLE);
    public static Label version = new Label(AppInfo.VERSION);
    public static Label author = new Label(AppInfo.AUTHOR);
    public static Label compile = new Label(AppInfo.COMPILE);
    public static Label email = new Label(AppInfo.EMAIL);

    static {
        stage.setScene(scene);
        stage.setWidth(300);
        stage.setHeight(220);
        stage.initOwner(IndexUI.stage);
        stage.setMaximized(false);
        stage.initModality(Modality.WINDOW_MODAL);
        stage.setTitle(AppInfo.ABOUT_TITLE);
        stage.setResizable(false);
        stage.setAlwaysOnTop(true);
        setPosition(imageView, 50, 20);
        setPosition(title, 100, 28);
        setPosition(T_VERSION, 60, 80);
        setPosition(version, 110, 80);
        setPosition(T_TIME, 60, 100);
        setPosition(compile, 110, 100);
        setPosition(T_AUTHOR, 60, 120);
        setPosition(author, 110, 120);
        setPosition(T_EMAIL, 60, 140);
        setPosition(email, 110, 140);
        title.setFont(new Font(24));
        imageView.setFitWidth(42);
        imageView.setFitHeight(42);
        ObservableList<Node> children = anchorPane.getChildren();
        children.add(imageView);
        children.add(T_VERSION);
        children.add(T_AUTHOR);
        children.add(T_EMAIL);
        children.add(title);
        children.add(version);
        children.add(author);
        children.add(compile);
        children.add(email);
        children.add(T_TIME);
    }

    private static void setPosition(Node node, int x, int y) {
        node.setLayoutX(x);
        node.setLayoutY(y);
    }
}
